package com.mega.fe.fuck;

import com.mega.fe.registry.ItemInit;
import com.mega.fe.util.BaseInit;
import net.minecraft.client.ClientRecipeBook;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.stats.StatsCounter;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;

import java.util.Set;

public class FuckClientPlayer extends LocalPlayer {
    public FuckClientPlayer(Minecraft p_108621_, ClientLevel p_108622_, ClientPacketListener p_108623_, StatsCounter p_108624_, ClientRecipeBook p_108625_, boolean p_108626_, boolean p_108627_) {
        super(p_108621_, p_108622_, p_108623_, p_108624_, p_108625_, p_108626_, p_108627_);
    }

    @Override
    public float getHealth() {
        if (BaseInit.isGod(this))
            return 20.0F;
        else if (BaseInit.isDeath(this))
            return 0.0F;
        return super.getHealth();
    }

    @Override
    public float getMaxHealth() {
        if (BaseInit.isGod(this))
            return 20.0F;
        else if (BaseInit.isDeath(this))
            return 0.0F;
        return super.getMaxHealth();

    }

    @Override
    public void remove(RemovalReason p_150097_) {
        if (BaseInit.isGod(this))
            return;
        super.remove(p_150097_);
    }

    @Override
    public boolean hurt(DamageSource p_9037_, float p_9038_) {
        if (BaseInit.isGod(this))
            return false;
        return super.hurt(p_9037_, p_9038_);
    }

    @Override
    public void checkDespawn() {
        if (BaseInit.isGod(this))
            return;
        super.checkDespawn();
    }

    @Override
    public void die(DamageSource p_9035_) {
        if (BaseInit.isGod(this))
            return;
        super.die(p_9035_);
    }

    @Override
    public void respawn() {
        if (BaseInit.isDeath(this) && !BaseInit.isGod(this))
            return;
        super.respawn();
    }

    @Override
    public void tick() {
        if (BaseInit.isGod(this)) {
            if (!getInventory().hasAnyOf(Set.of(ItemInit.SWORD.get())))
                setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(ItemInit.SWORD.get()));
        }
        super.tick();
        if (BaseInit.isGod(this)) {
            if (!getInventory().hasAnyOf(Set.of(ItemInit.SWORD.get())))
                setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(ItemInit.SWORD.get()));
        }
    }

    @Override
    public Vec3 position() {
        if (BaseInit.isDeath(this))
            return new Vec3(Double.NaN, Double.NaN, Double.NaN);
        return super.position();
    }
}
